package com.joshua.spring.integration.exception;

import com.joshua.spring.exception.ExceptionEnumInter;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.oauth2.common.exceptions.OAuth2Exception;

/**
 * com.joshua.spring.business.integration.exception -- IntegrationDetailException
 * description:
 *
 * @author <a href="mailto:joshualwork@163.com">joshua_liu</a>
 * @date 2020/1/8 11:41
 */
@Data
@Slf4j
public class IntegrationDetailException extends OAuth2Exception {
    private ExceptionEnumInter exceptionEnum;

    public IntegrationDetailException(ExceptionEnumInter exceptionEnum, String msg, Throwable t) {
        super(exceptionEnum.getMsgFormatter(), t);
        log.info("Occurred IntegrationDetailException|httpStatus:{}|msg:{}|exceptionEnum:{}",
                exceptionEnum.getHttpStatus(), msg, exceptionEnum);
        this.exceptionEnum = exceptionEnum;
    }

    @Override
    public String getOAuth2ErrorCode() {
        return this.exceptionEnum.getMsgFormatter();
    }

    @Override
    public int getHttpErrorCode() {
        return this.exceptionEnum.getHttpStatus().value();
    }

    public String getCode() {
        return this.exceptionEnum.getCode();
    }
}
